package org.kirhgoff.mathbot;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.io.PrintStream;

public class LOGGER {
	private static OutputStream outputStream = null;
	
	static {
		try {
			File file = new File("C:/ProjectsDev/ai-contest-java/mathbot.log");
			if (!file.exists()) {
				file.createNewFile();
			}
			outputStream = new FileOutputStream(file);
		} catch (Exception e) {
			throw new RuntimeException(e);
		}
	}

	public static void info(String string) {
		try {
			outputStream.write((string + "\n").getBytes());
			// outputStream.close(); //not sure which one calls each other
		} catch (Exception e) {
			throw new RuntimeException(e);
		}
	}

	public static void error(Exception e) {
		try {
			e.printStackTrace(new PrintStream(outputStream));
			outputStream.flush();
		} catch (Exception ex) {
			throw new RuntimeException(ex);
		}

	}

	public static void debug(String string) {
		if (Properties.DEBUG) {
			info (string);
		}
		
	}

	public static void flush () {
		try {
			outputStream.flush();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
}
